## Script (Python) "toLocalizedTime"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=time=None, e_time=None,
##title=
##
# The time parameter must be either a string that is suitable for
# initializing a DateTime or a DateTime object.
# Returns a localized string.

from Products.CMFCore.utils import getToolByName
from DateTime import DateTime

ch_lang = ('ja', 'zh-tw')    

bound = context.portal_languages.getLanguageBindings()
try:
    lang = bound[0]
except IndexError:
    lang = 'zh-tw'

if not isinstance(time, DateTime):
    time=DateTime(time)
if not isinstance(e_time, DateTime):
    e_time=DateTime(e_time)

if lang in ch_lang:
    vDateStr = '%s年%s月%s日' % (time.year(),time.month(),time.day())
    vEndDateStr = '%s年%s月%s日' % (e_time.year(),e_time.month(),e_time.day())
    
    if vDateStr == vEndDateStr:
        vReturnTimeStr = '%s %s:%.2d～%s:%.2d' % (vDateStr, time.hour(), time.minute(), e_time.hour(), e_time.minute())
    else:
        vReturnTimeStr = '%s %s:%s ～ %s %s:%.2d' % (vDateStr, time.hour(), time.minute(),vEndDateStr, e_time.hour(), e_time.minute())
    
else:
    vDateStr = '%s-%s-%s' % (time.year(),time.month(),time.day())
    vEndDateStr = '%s-%s-%s' % (e_time.year(),e_time.month(),e_time.day())
    
    if vDateStr == vEndDateStr:
        vReturnTimeStr = '%s %s:%.2d - %s:%.2d' % (vDateStr, time.hour(), time.minute(), e_time.hour(), e_time.minute())
    else:
        vReturnTimeStr = '%s %s:%.2d - %s %s:%.2d' % (vDateStr, time.hour(), time.minute(),vEndDateStr, e_time.hour(), e_time.minute())


return vReturnTimeStr #context.restrictedTraverse('@@plone').toLocalizedTime(time, long_format)
